package com.community.backend.service.impl;

import com.community.backend.mapper.PatrolMapper;
import com.community.backend.pojo.Patrol;
import com.community.backend.pojo.dto.PatrolQueryDTO;
import com.community.backend.service.PatrolService;
import com.community.backend.utils.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

@Service
public class PatrolServiceImpl implements PatrolService {
    private final PatrolMapper patrolMapper;

    public PatrolServiceImpl(PatrolMapper patrolMapper) {
        this.patrolMapper = patrolMapper;
    }

    @Override
    public PageResult pageQuery(PatrolQueryDTO patrolQueryDTO) {
        PageHelper.startPage(patrolQueryDTO.getCurrentPage(), patrolQueryDTO.getPageSize());
        Page<Patrol> page = patrolMapper.pageQuery(patrolQueryDTO);
        return new PageResult(page.getPages(), page.getResult());
    }

    @Override
    public void update(Patrol patrol) {
        patrolMapper.update(patrol);
    }

    @Override
    public void save(Patrol patrol) {
        patrolMapper.insert(patrol);
    }

    @Override
    public void deleteById(Integer id) {
        patrolMapper.deleteById(id);
    }

    @Override
    public Patrol selectById(Integer id) {
        return patrolMapper.selectById(id);
    }
}
